package ${package_controller};
import ${package_pojo}.${Table}${pojoSuffix};
import ${package_service}.${Table}Service;
import com.github.pagehelper.PageInfo;
<#if swagger==true>import io.swagger.annotations.*;</#if>
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @Author huanmin
 */
<#if swagger==true>@Api(tags = "${Table}Controller")</#if>
@RestController
@RequestMapping("/${table}")
@CrossOrigin
public class ${Table}Controller {

    @Autowired
    private ${Table}Service ${table}Service;


    /***
     * ${Table}分页条件搜索实现
     * @param ${table}${pojoSuffix}
     * @param page
     * @param size
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${Table}条件分页查询",notes = "分页条件查询${Table}方法详情",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${table}${pojoSuffix}", name = "${table}${pojoSuffix}", value = "${table}${pojoSuffix}", required = true, dataType = "${Table}${pojoSuffix}"),
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    </#if>
    @PostMapping(value = "/search/{page}/{size}" )
    public ResponseEntity<PageInfo<${Table}${pojoSuffix}>>  select${Table}Page(@RequestBody  ${Table}${pojoSuffix} ${table}${pojoSuffix}, @PathVariable  int page, @PathVariable  int size){
        //调用${Table}Service实现分页条件查询${Table}
        PageInfo<${Table}${pojoSuffix}> pageInfo = ${table}Service.select${Table}Page(${table}${pojoSuffix}, page, size);
        return ResponseEntity.ok(pageInfo);
    }

    /***
     * ${Table}分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${Table}分页查询",notes = "分页查询${Table}方法详情",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    </#if>
    @GetMapping(value = "/search/{page}/{size}" )
    public ResponseEntity<PageInfo<${Table}${pojoSuffix}>>  select${Table}Page(@PathVariable  int page, @PathVariable  int size){
        //调用${Table}Service实现分页查询${Table}
        PageInfo<${Table}${pojoSuffix}> pageInfo = ${table}Service.select${Table}Page(page, size);
        return ResponseEntity.ok(pageInfo);
    }



    /***
     * 查询${TableName}表的总条数
     * @return Integer
     */

    <#if swagger==true>
    @ApiOperation(value = "查询${TableName}表的总条数",notes = "查询${TableName}表的总条数",tags = {"${Table}Controller"})
    </#if>
    @GetMapping(value = "/select${Table}Count" )
    public  ResponseEntity<Integer> select${Table}Count(){
        return  ResponseEntity.ok(${table}Service.select${Table}Count());
    }


    /***
     * 查询${TableName}表的全部数据
     * @return List<${Table}>
     */
    <#if swagger==true>
    @ApiOperation(value = "查询${TableName}表的全部数据",notes = "查询${TableName}表的全部数据",tags = {"${Table}Controller"})
    </#if>
    @GetMapping(value = "/select${Table}s" )
    public ResponseEntity<List<${Table}${pojoSuffix}>> select${Table}s(){
        return ResponseEntity.ok(${table}Service.select${Table}s());
    }

    /***
     * 查询${TableName}表的主键id对应的值
     * @return ${Table}
     */
    <#if swagger==true>
    @ApiOperation(value = "查询${TableName}表的主键id对应的值",notes = "查询${TableName}表的主键id对应的值",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${mapId['o_id']}", name = "${mapId['o_id']}", value = "${mapId['o_id']}", required = true, dataType = "Integer"),
    })
    </#if>
   @GetMapping(value = "/select${Table}ById/{${mapId["o_id"]}}")
   public ResponseEntity<${Table}${pojoSuffix}> select${Table}ById(@PathVariable  Integer ${mapId["o_id"]}){
        return ResponseEntity.ok(${table}Service.select${Table}ById(${mapId["o_id"]}));
    }

    /***
     * 查询t_user表的指定条件(User)的值 (包含: 自定义排序 ,自定义分页)
     * @return List<${Table}>
     */
    <#if swagger==true>
    @ApiOperation(value = "查询${TableName}表的指定条件(${Table})的值 (包含: 自定义排序 ,自定义分页)",notes = "查询${TableName}表的指定条件(${Table})的值 (包含: 自定义排序 ,自定义分页)",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${table}${pojoSuffix}", name = "${table}${pojoSuffix}", value = "${table}${pojoSuffix}", required = true, dataType = "Integer"),
    })
    </#if>
    @PostMapping(value = "/select${Table}By${Table}" )
    public ResponseEntity<List<${Table}${pojoSuffix}>>  select${Table}By${Table}(@RequestBody ${Table}${pojoSuffix} ${table}${pojoSuffix}){
        return ResponseEntity.ok(${table}Service.select${Table}By${Table}(${table}${pojoSuffix}));
    }


    /***
     * 自定义查询${TableName}表的指定值,自定义查询(包含: 自定义列,自定义查询条件 , 自定义分组(分组后的赛选),自定义排序 ,自定义分页)
     * @return List<${Table}>
     */
    <#if swagger==true>
    @ApiOperation(value = "自定义查询${TableName}表的指定值,自定义查询(包含: 自定义列,自定义查询条件 , 自定义分组(分组后的赛选),自定义排序 ,自定义分页)",notes = "自定义查询${TableName}表的指定值,自定义查询(包含: 自定义列,自定义查询条件 , 自定义分组(分组后的赛选),自定义排序 ,自定义分页)",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${table}${pojoSuffix}", name = "${table}${pojoSuffix}", value = "${table}${pojoSuffix}", required = true, dataType = "${Table}${pojoSuffix}"),
    })
    </#if>
    @PostMapping(value = "/select${Table}ByCustom" )
    public ResponseEntity<List<${Table}${pojoSuffix}>>  select${Table}ByCustom(@RequestBody ${Table}${pojoSuffix} ${table}${pojoSuffix}){
        return ResponseEntity.ok(${table}Service.select${Table}ByCustom(${table}${pojoSuffix}));
    }



    /***
     * 插入一个${Table}${pojoSuffix}对象的数据到数据库${TableName}表中,`包括` 属性值为null的数据  ,不包括主键因为一般主键都是自动生成的
     * @return Integer
     */
    <#if swagger==true>
    @ApiOperation(value = "插入一个${Table}对象的数据到数据库${TableName}表中,`包括` 属性值为null的数据  ,不包括主键因为一般主键都是自动生成的",notes = "插入一个${Table}对象的数据到数据库${TableName}表中,`包括` 属性值为null的数据  ,不包括主键因为一般主键都是自动生成的",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${table}${pojoSuffix}", name = "${table}${pojoSuffix}", value = "${table}${pojoSuffix}", required = true, dataType = "${Table}${pojoSuffix}"),
    })
    </#if>
    @PostMapping(value = "/insert${Table}By${Table}")
    public ResponseEntity<Integer> insert${Table}By${Table}(@RequestBody ${Table}${pojoSuffix} ${table}${pojoSuffix}){
        return ResponseEntity.ok(${table}Service.insert${Table}By${Table}(${table}${pojoSuffix}));
    }


    /***
     * 插入一个${Table}${pojoSuffix}对象的数据到数据库${TableName}表中,`不包括` 属性值为null的数据 和 不包括主键因为一般主键都是自动生成的
     * @return Integer
     */
    <#if swagger==true>
    @ApiOperation(value = "插入一个${Table}对象的数据到数据库${TableName}表中,`不包括` 属性值为null的数据 和 不包括主键因为一般主键都是自动生成的",notes = "插入一个${Table}对象的数据到数据库${TableName}表中,`不包括` 属性值为null的数据 和 不包括主键因为一般主键都是自动生成的",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${table}${pojoSuffix}", name = "${table}${pojoSuffix}", value = "${table}${pojoSuffix}", required = true, dataType = "${Table}${pojoSuffix}"),
    })
    </#if>
    @PostMapping(value = "/insert${Table}By${Table}IsNotNull")
    public ResponseEntity<Integer> insert${Table}By${Table}IsNotNull(@RequestBody ${Table}${pojoSuffix} ${table}${pojoSuffix}){
        return ResponseEntity.ok(${table}Service.insert${Table}By${Table}IsNotNull(${table}${pojoSuffix}));
    }


    /***
     * 插入一批${Table}${pojoSuffix}对象的数据到数据库${TableName}表中,包括属性值为null的数据  ,不包括主键因为一般主键都是自动生成的
     * @return Integer
     */
    <#if swagger==true>
    @ApiOperation(value = "插入一批${Table}对象的数据到数据库${TableName}表中,包括属性值为null的数据  ,不包括主键因为一般主键都是自动生成的",notes = "插入一批${Table}对象的数据到数据库${TableName}表中,包括属性值为null的数据  ,不包括主键因为一般主键都是自动生成的",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${table}${pojoSuffix}s", name = "${table}${pojoSuffix}s", value = "${table}${pojoSuffix}s", required = true, dataType = "List<${Table}${pojoSuffix}>"),
    })
    </#if>
    @PostMapping(value = "/batchInsert${Table}By${Table}")
    public ResponseEntity<Integer> batchInsert${Table}By${Table}(@RequestBody List<${Table}${pojoSuffix}> ${table}${pojoSuffix}s){
        return  ResponseEntity.ok(${table}Service.batchInsert${Table}By${Table}(${table}${pojoSuffix}s));
    }

    /***
     * 插入一批${Table}${pojoSuffix}对象的数据到数据库${TableName}表中,不包括属性值为null的数据 和 不包括主键因为一般主键都是自动生成的
     * @return Integer
     */
    <#if swagger==true>
    @ApiOperation(value = "插入一批${Table}${pojoSuffix}对象的数据到数据库${TableName}表中,不包括属性值为null的数据 和 不包括主键因为一般主键都是自动生成的",notes = "插入一批${Table}${pojoSuffix}对象的数据到数据库${TableName}表中,不包括属性值为null的数据 和 不包括主键因为一般主键都是自动生成的",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${table}${pojoSuffix}s", name = "${table}${pojoSuffix}s", value = "${table}${pojoSuffix}s", required = true, dataType = "List<${Table}${pojoSuffix}>"),
    })
    </#if>
    @PostMapping(value = "/batchInsert${Table}By${Table}NotNull")
    public ResponseEntity<Integer> batchInsert${Table}By${Table}NotNull(@RequestBody List<${Table}${pojoSuffix}> ${table}${pojoSuffix}s){
        return ResponseEntity.ok(${table}Service.batchInsert${Table}By${Table}NotNull(${table}${pojoSuffix}s));
    }




    /***
     * 根据主键ID修改${TableName}表中,括属性值为null的数据
     * @return Integer
     */
    <#if swagger==true>
    @ApiOperation(value = "根据主键ID修改${TableName}表中,括属性值为null的数据",notes = "根据主键ID修改${TableName}表中,括属性值为null的数据",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${table}${pojoSuffix}", name = "${table}${pojoSuffix}", value = "${table}${pojoSuffix}", required = true, dataType = "${Table}${pojoSuffix}"),
    })

    </#if>
    @PutMapping(value = "/update${Table}ById")
    public ResponseEntity<Integer> update${Table}ById(@RequestBody ${Table}${pojoSuffix} ${table}${pojoSuffix}){
        return ResponseEntity.ok(${table}Service.update${Table}ById(${table}${pojoSuffix}));
    }



    /***
     * 根据主键ID修改${TableName}表中,不包括属性值为null的数据
     * @return Integer
     */
    <#if swagger==true>
    @ApiOperation(value = "根据主键ID修改${TableName}表中,不包括属性值为null的数据",notes = "根据主键ID修改${TableName}表中,不包括属性值为null的数据",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${table}${pojoSuffix}", name = "${table}${pojoSuffix}", value = "${table}${pojoSuffix}", required = true, dataType = "${Table}${pojoSuffix}"),
    })
    </#if>
    @PutMapping(value = "/update${Table}ByIdNotNull")
    public ResponseEntity<Integer> update${Table}ByIdNotNull(@RequestBody ${Table}${pojoSuffix} ${table}${pojoSuffix}){
        return  ResponseEntity.ok(${table}Service.update${Table}ByIdNotNull(${table}${pojoSuffix}));
    }

    /***
     * 根据主键ID删除${TableName}表中指定数据
     * @return Integer
     */
    <#if swagger==true>
    @ApiOperation(value = "根据主键ID删除${TableName}表中指定数据",notes = "根据主键ID删除${TableName}表中指定数据",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${mapId['o_id']}", name = "${mapId['o_id']}", value = "${mapId['o_id']}", required = true, dataType = "Integer"),
    })
    </#if>
    @DeleteMapping(value = "/delete${Table}ById/{${mapId["o_id"]}}")
    public  ResponseEntity<Integer> delete${Table}ById(@PathVariable Integer ${mapId["o_id"]}){
        return ResponseEntity.ok(${table}Service.delete${Table}ById(${mapId["o_id"]}));
    }


    /***
     * 批量主键ID删除${TableName}表中指定数据
     * @return Integer
     */
    <#if swagger==true>
    @ApiOperation(value = "批量主键ID删除${TableName}表中指定数据",notes = "批量主键ID删除${TableName}表中指定数据",tags = {"${Table}Controller"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "${mapId['o_id']}s", name = "${mapId['o_id']}s", value = "${mapId['o_id']}s", required = true, dataType = "Integer"),
    })
    </#if>
    @DeleteMapping(value = "/batchDelete${Table}ById")
    public ResponseEntity<Integer> batchDelete${Table}ById(@RequestParam List<Integer> ${mapId["o_id"]}s){
        return ResponseEntity.ok(${table}Service.batchDelete${Table}ById(${mapId["o_id"]}s));
    }



    /***
     * 清空${TableName}表的数据,主键自增也会重置
     * @return Integer
     */
    <#if swagger==true>
    @ApiOperation(value = "清空${TableName}表的数据,主键自增也会重置",notes = "清空${TableName}表的数据,主键自增也会重置",tags = {"${Table}Controller"})
    </#if>
    @DeleteMapping(value = "/clear${Table}All")
    public ResponseEntity<Integer> clear${Table}All(){
        return  ResponseEntity.ok(${table}Service.clear${Table}All());
    }


}
